﻿#pragma once

#include <QObject>
#include <QDebug>
#include <QMessageBox>

#include <opencv.hpp>

using namespace std;
using namespace cv;

class CalibrateCamera :public QObject
{
	Q_OBJECT
public:
	CalibrateCamera();

private:

	bool saveCameraParams(const std::string& filename, cv::Size imageSize, float aspectRatio, int flags,
		const cv::Mat& cameraMatrix, const cv::Mat& distCoeffs, double totalAvgErr);

	int squaresX = 5;
	int squaresY = 7;
	float squareLength = 0.025f;
	float markerLength = 0.018f;

	aruco::Dictionary _dictionary;
	aruco::CharucoParameters _charucoParams;
	aruco::DetectorParameters _detectorParams;

	aruco::CharucoBoard* _board;
	aruco::CharucoDetector* _detector;

	vector<Mat> allCharucoCorners, allCharucoIds;
	vector<vector<Point2f>> allImagePoints;
	vector<vector<Point3f>> allObjectPoints;
	vector<Mat> allImages;
	Size imageSize;

	bool _calibrating;

public:
	void set_calibrate_flag(bool flag);
	void reset();

public slots:
	void process(cv::Mat mat);
};

